package com.fjc.service;

import com.fjc.dao.SysUserMapper;
import com.fjc.domain.ResultObject;
import com.fjc.domain.SysUser;
import com.fjc.domain.SysUserExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class SysUserService {
    @Autowired
    private SysUserMapper sysUserMapper;

    public ResultObject login(SysUser user, HttpServletRequest request){
        SysUserExample sysUserExample = new SysUserExample();
        sysUserExample.createCriteria().andUsernameEqualTo(user.getUsername());
        List<SysUser> list = sysUserMapper.selectByExample(sysUserExample);
        if(list.size() <= 0){
            return new ResultObject(-1,"该用户不存在");
        }else{
            if(list.get(0).getPassword().equals(user.getPassword())){
                request.getSession().setAttribute("user",user);
                return new ResultObject(0,"登录成功");
            }else{
                return new ResultObject(-1,"帐号或用户名错误");
            }
        }

    }

}
